<template>
  <div class="login">
    <div class="con">
      <h3 class="text-center h">登陆</h3>
      <el-input v-model="user.username" clearable placeholder="请输入用户名"></el-input>
      <el-input v-model="user.password" clearable show-password placeholder="请输入密码"></el-input>
      <div class="text-center">
        <el-button type="primary" plain round @click="login">登陆</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { requserlogin } from "../../http/api";
export default {
  props: [],
  data() {
    return {
      user: {
        username: "",
        password: ""
      }
    };
  },
  computed: {
    ...mapGetters({
      userInfo: "userInfo"
    })
  },
  mounted() {},
  methods: {
    ...mapActions({
      changeUserInfo: "changeUserInfo"
    }),
    //登陆
    login() {
      requserlogin(this.user).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          //存入vuex和本地存储
          this.changeUserInfo(res.data.list);
          this.$router.push("/")
        }
      });
    }
  }
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @primary-light, @primary-deep);
  position: relative;
  .con {
    position: absolute;
    width: 380px;
    padding: 10px;
    background: #ffffff;
    border-radius: @padding10;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
  .el-input {
    margin-bottom: @margin20;
  }
}
</style>